/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package applet.Mains;

import org.apache.log4j.*;

import library.RemoteControl.*;
import applet.Forms.*;

/**
 * This class is used for testing purposes only : it embeds the applet in a 
 * JFrame.
 * This class contains a static main method.
 * 
 * La classe d'une applet héritant de la classe Panel, il est possible
 * d'ajouter une applet à une fenêtre de classe Frame. Grâce à cette 
 * caractéristique, vous pouvez ajouter à la plupart de vos applets la 
 * faculté d'être utilisées comme applications isolées, en leur ajoutant 
 * une méthode main () qui crée une instance de Frame pour y ajouter une 
 * instance de votre applet (les limitations de ce système sont décrites 
 * au chapitre sur les applets).
 * 
 * @author JNC
 */
public class Main_Applet_Application {

    /**
     * The log4j log
     */
    private static final Logger _logger = Logger.getLogger(Main_Applet_Application.class);
    
    /**
     * The static main method.
     * @param args
     * Arguments de l'application
     */
    public static void main(String args[]) {
        javax.swing.JFrame frame = null;
        JApplet_Form applet = null;        
        boolean mustStop = false;
              
        _logger.debug("Start");
        _logger.debug("Current directory = " + System.getProperty("user.dir"));
  
        // Creates a frame
        // --------------
        frame = new javax.swing.JFrame();
        
        // Creates an applet
        // ----------------
        // The configuration file will be found in the constructor of 
        // JApplet_Form
        try {
            _logger.debug("Creating the JApplet_Form");
            applet = new JApplet_Form();
        }
        catch (UnknownClassException exception) {
            _logger.error("Exception_UnknownClassException caught while registering Main_Applet(Interface_Form) : " + exception);
            mustStop = true;
        }
        
        // Makes the frame visible
        // -----------------------
        if (! mustStop) {
            // The frame should be set visible before calling applet.init() 
            // otherwise the focus is not given to the GO/CANCEL button
            // The initial focus is given as the last instruction of the 
            // applet.init() method. To be effective, it seems the frame must be
            // visble and the focus must be given as the last instruction before
            // giving control to the user.
            frame.setVisible(true);
            
            // Adds the applet to the JFrame
            // JApplet inherits from JPanel, so it is enough to add it into 
            // JFrame
            frame.add("Center", applet);
        
            // Starts the applet (otherwise, the frame is empty)
            applet.init();
        
            // Sizes the JFrame accordingly to its content
            // (must be called after the applet started, otherwise has no 
            // effect)
            frame.pack();
        }
    }
}